package com.kevin.mapping.script.node.stmt;

import com.kevin.mapping.script.engine.JSONEnv;
import com.kevin.mapping.script.lexer.Token;

public class IfStmt extends Stmt {
    private Stmt condition;
    private Stmt stmt;
    private Stmt next;

    public IfStmt(Token token, Stmt condition, Stmt stmt) {
        super(token);
        this.condition = condition;
        this.stmt = stmt;
    }

    public Stmt getCondition() {
        return condition;
    }

    public void setCondition(Stmt condition) {
        this.condition = condition;
    }

    public Stmt getNext() {
        return next;
    }

    public void setNext(Stmt next) {
        this.next = next;
    }

    public Stmt getStmt() {
        return stmt;
    }

    public void setStmt(Stmt stmt) {
        this.stmt = stmt;
    }

    @Override
    public Token execute(JSONEnv env) {
        Object value = condition.getValue(env);
        if (value instanceof Boolean) {
            if ((boolean) value) {
                return stmt.execute(env);
            }
        }

        return null;
    }
}
